package com.stores.unitTests.admin;

import com.stores.unitTests.LocalDatabase;
import com.stores.v1.entity.Address;
import com.stores.v1.entity.Person;
import com.stores.v1.entity.Phone;
import com.stores.v1.entity.SiteAdmin;
import com.stores.v1.entity.SiteManager;
import com.stores.v1.entity.StoreManager;
import com.stores.v1.entity.UserAccount;
import com.stores.v1.model.AccessControlException;
import com.stores.v1.model.DatabaseCommandException;
import com.stores.v1.model.DatabaseTransactionException;
import com.stores.v1.model.PersonModel;
import com.stores.v1.model.SiteAdminModel;
import com.stores.v1.security.AccessControl;
import com.stores.v1.toolset.DatabaseInitializationException;

public class PersonFixtureHelper {

	/****
	 * 
	 * @param id
	 * @throws DatabaseInitializationException
	 * @throws DatabaseTransactionException
	 */
	public void deleteUser(int id) throws DatabaseInitializationException,
			DatabaseTransactionException {
		SiteAdmin admin = new SiteAdmin();
		UserAccount account = new UserAccount();
		account.setId(1);
		admin.setAccount(account);

		PersonModel model = new SiteAdminModel(admin);
		model.setDatabase(new LocalDatabase());

		Person p = new SiteAdmin();
		p.setId(id);
		model.deleteUser(p);
	}

	/****
	 * 
	 * @param admin
	 * @return
	 * @throws DatabaseInitializationException
	 * @throws DatabaseTransactionException
	 * @throws AccessControlException
	 * @throws DatabaseCommandException
	 */
	public int createSiteAdminUser(SiteAdmin admin)
			throws DatabaseInitializationException,
			DatabaseTransactionException, AccessControlException,
			DatabaseCommandException {
		PersonModel model = new SiteAdminModel(admin);
		model.setDatabase(new LocalDatabase());
		model.setUserContext(admin);
		model.setAccessControl(new AccessControl());

		SiteAdmin newAdmin = new SiteAdmin();
		newAdmin.setFirstName("Annu");
		newAdmin.setLastName("Sahay");
		newAdmin.setEmailAddress("annu16sahay@gmail.com");

		Address address = new Address();
		address.setHouse("Flat# 203, Krishna Krupa");
		address.setLocality("Kagadaspura");
		newAdmin.setAddress(address);

		Phone phone = new Phone();
		phone.setAreaCode("080");
		phone.setNumber("+919980955558");
		newAdmin.setPhone(phone);

		UserAccount account = new UserAccount();
		account.setPassword("sonumonu");
		newAdmin.setAccount(account);

		int id = model.createUser(newAdmin);
		return id;
	}

	public Person getNewStoreManager() {
		// TODO Auto-generated method stub
		Person storeManager = new StoreManager();
		storeManager.setFirstName("Store Manager");
		storeManager.setLastName("01");
		storeManager.setEmailAddress("sm01@gmail.com");

		Address address = new Address();
		address.setHouse("Flat# 203, Krishna Krupa");
		address.setLocality("Kagadaspura");
		storeManager.setAddress(address);

		Phone phone = new Phone();
		phone.setAreaCode("080");
		phone.setNumber("+919980955558");
		storeManager.setPhone(phone);

		UserAccount account = new UserAccount();
		account.setPassword("sonumonu");
		storeManager.setAccount(account);

		return storeManager;
	}
	
	/***
	 * 
	 * @return
	 */
	public Person getNewSiteManager() {
		// TODO Auto-generated method stub
		Person siteManager = new SiteManager();
		siteManager.setFirstName("Site Manager");
		siteManager.setLastName("01");
		siteManager.setEmailAddress("sitemgr@gmail.com");

		Address address = new Address();
		address.setHouse("Flat# 203, Krishna Krupa");
		address.setLocality("Kagadaspura");
		siteManager.setAddress(address);

		Phone phone = new Phone();
		phone.setAreaCode("080");
		phone.setNumber("+919980955558");
		siteManager.setPhone(phone);

		UserAccount account = new UserAccount();
		account.setPassword("sonumonu");
		siteManager.setAccount(account);

		return siteManager;
	}
}
